package cn.iocoder.yudao.module.etl.controller.admin.dataset;

import cn.iocoder.yudao.module.etl.dal.dataobject.DatasetGroup;
import cn.iocoder.yudao.module.etl.dto.dataset.DataSetGroupDTO;
import cn.iocoder.yudao.module.etl.request.dataset.DataSetGroupRequest;
import cn.iocoder.yudao.module.etl.service.KettleService;
import cn.iocoder.yudao.module.etl.service.dataset.DataSetGroupService;
import cn.iocoder.yudao.module.etl.utils.ResultHolder;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author gin
 * @Date 2021/2/20 8:29 下午
 */
@Api(tags = "数据集：数据集组")
@ApiSupport(order = 40)
@RestController
@RequestMapping("etl/dataset/group")
public class DataSetGroupController {
    @Resource
    private DataSetGroupService dataSetGroupService;
    @Resource
    private KettleService kettleService;

    @ApiOperation("保存")
    @PostMapping("/save")
    public ResultHolder save(@RequestBody DatasetGroup datasetGroup) throws Exception {
        DataSetGroupDTO save = dataSetGroupService.save(datasetGroup);
        return ResultHolder.success(save);
    }

    @ApiIgnore
    @PostMapping("/tree")
    public ResultHolder tree(@RequestBody DataSetGroupRequest datasetGroup) {
        List<DataSetGroupDTO> tree = dataSetGroupService.tree(datasetGroup);
        return ResultHolder.success(tree);
    }

    @ApiIgnore
    @PostMapping("/treeNode")
    public ResultHolder treeNode(@RequestBody DataSetGroupRequest datasetGroup) {
        List<DataSetGroupDTO> dataSetGroupDTOS = dataSetGroupService.treeNode(datasetGroup);
        return ResultHolder.success(dataSetGroupDTOS);
    }

    @ApiOperation("删除")
    @PostMapping("/delete/{id}")
    public void delete(@PathVariable String id) throws Exception {
        DatasetGroup datasetGroup = dataSetGroupService.getScene(id);
//        SysLogDTO sysLogDTO = DeLogUtils.buildLog(SysLogConstants.OPERATE_TYPE.DELETE, SysLogConstants.SOURCE_TYPE.DATASET, id, datasetGroup.getPid(), null, null);
        dataSetGroupService.delete(id);
//        DeLogUtils.save(sysLogDTO);
    }

    @ApiIgnore
    @PostMapping("/getScene/{id}")
    public ResultHolder getScene(@PathVariable String id) {
        DatasetGroup scene = dataSetGroupService.getScene(id);
        return ResultHolder.success(scene);
    }

    @ApiIgnore
    @PostMapping("/isKettleRunning")
    public ResultHolder isKettleRunning() {
        boolean kettleRunning = kettleService.isKettleRunning();
        return ResultHolder.success(kettleRunning);
    }
}
